package com.adcc.ags.gms.mq.controller;

import com.adcc.ags.gms.core.util.Constant;
import com.adcc.ags.gms.core.util.LogFactory;
import com.adcc.ags.gms.core.vo.ResultState;
import com.adcc.ags.gms.core.vo.ResultVO;
import com.adcc.ags.gms.mq.service.TopicService;
import com.adcc.ags.gms.mq.vo.TopicVO;
import com.google.common.base.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 会话控制层
 */
@Controller
@RequestMapping(value="/topic",produces = MediaType.APPLICATION_JSON_VALUE)
public class TopicController {

    @Autowired
    private LogFactory log;

    @Autowired
    private TopicService topicService;

    @RequestMapping(value = "/findAllTopic", method = RequestMethod.GET)
    public @ResponseBody ResultVO findAllTopic(){
        ResultVO resultVO = new ResultVO();
        try {
            Optional<List<TopicVO>> optional = topicService.findAllTopic();
            if(optional.isPresent()){
                List<TopicVO> list = optional.get();
                resultVO.getData().put("topicVO",list);
            }else{
                resultVO.setCode(-1);
                resultVO.setState(ResultState.FAILURE);
                resultVO.setReason(Constant.GMS_PCF_ERROR);
            }
        } catch (Exception ex) {
            log.error(TopicController.class, "findAllTopic() error", ex);
            resultVO.setCode(-1);
            resultVO.setState(ResultState.FAILURE);
            resultVO.setReason(Constant.GMS_SERVER_ERROR);
        }
        return resultVO;
    }
}

